package com.wolfking.converter.transform.base;


import com.google.common.collect.Sets;
import com.wolfking.converter.transform.FieldTransform;

import java.util.Set;

public class DoubleFieldTransform implements FieldTransform<Double> {

    private final Set<Class<?>> classes = Sets.newHashSet(Double.class, double.class);

    @Override
    public boolean canTransform(Class<?> fieldType) {
        return classes.contains(fieldType);
    }

    @Override
    public Double transform(Object value) {
        for (Class<?> clazz : classes) {
            if (clazz.isAssignableFrom(value.getClass())) {
                return (Double)value;
            }
        }
        return Double.parseDouble(value.toString());
    }
}
